package com.ck.admin.common;

import com.ck.admin.base.BaseCode;
import com.fasterxml.jackson.annotation.JsonView;

/**
 * 
 * <p>Title:ResultVo<p>
 * <p>Description:ResultVo.java<p>
 * @author admin
 * @date 2017年8月28日 上午9:20:39
 */
public class Result<T> {
    private Integer code;

    private String msg;

    private T data;

    public Integer getCode() {
        return this.code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Result(T data) {
        this.code = BaseCode.SUCCESS.getCode();
        this.msg = BaseCode.SUCCESS.getMsg();
        this.data = data;
    }

    public Result() {
        this.code = BaseCode.SUCCESS.getCode();
        this.msg = BaseCode.SUCCESS.getMsg();
    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static Result fail() {
        return fail(BaseCode.FAIL.getCode(), BaseCode.FAIL.getMsg());
    }

    public static <T> Result<T> fail(String msg) {
        return fail(BaseCode.FAIL.getCode(), msg);
    }

    public static <T> Result<T> fail(int code, String msg) {
        Result<T> r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }

    public static <T> Result<T> success() {
        return new Result();
    }

    public static <T> Result<T> success(T t) {
        Result<T> r = new Result();
        r.setData(t);
        return r;
    }
    
}
